package LeetCode._01_树;

public class _701_二叉搜索树中的插入操作 {
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    public TreeNode insertIntoBST(TreeNode root, int val) {
        if(root == null) return new TreeNode(val); //找到了合适的位置

        if(root.val < val){
            root.right = insertIntoBST(root.right,val);
        }

        if(root.val > val){
            root.left =  insertIntoBST(root.left,val);
        }
        return root;
    }

}
